<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <script>

        function filechange(e) {
            var file = $('#filed').get(0).files[0];
            var fileSize = file.size,
                fileType = file.type;
            if (file.name.lastIndexOf('.') == -1) {
                $.dialog({
                    content: '路径不正确',
                    time: 2000
                });
                return false;
            }
            var AllImgExt = ".jpg|.jpeg|.gif|.bmp|.png|.swf|";
            var extName = file.name.substring(file.name.lastIndexOf(".")).toLowerCase();
            if (AllImgExt.indexOf(extName + "|") == -1) {
                $.dialog({
                    content: '非法图片格式',
                    time: 2000
                });
                return false;
            }
            if (fileSize < 3145728) {
                if (window.FileReader) {
                    var reader = new FileReader(); reader.readAsBinaryString(file);
                    reader.onload = function (e) {
                        var formData = new FormData(); formData.append("imgs", file); $.ajax({
                            url: "",//后台地址
                            type: 'post', contentType: "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",//格式转换为binary
                            data: formData, processData: false, // 使数据不做处理
                            contentType: false, dataType: 'json', success: function (d) { }
                        })
                    }
                }
            } else { $.dialog({ content: '图片大小超过限制', time: 2000 }); return false; }
        }
    </script>
</body>

</html>